Firebase Cloud Functions are serverless functions that run in the cloud in response to events triggered by Firebase features and HTTPS requests. Think of them as the backend server for your FireApp application that automatically scales and manages infrastructure for you.
FireApp's Cloud Functions serve as the complete backend infrastructure for your messaging application. Here's how they work:
When a user sends a message in your app, the following happens:
sendMessageNotification function automatically triggersuserMessages nodeUser A sends message → Firebase Database → Cloud Function →
Push Notification → User B receives notification → App fetches message
For group messages, the system:
Here are the main Cloud Functions powering your FireApp backend:
| Function Name | Trigger | Purpose |
|---|---|---|
sendMessageNotification |
New message in /messages/{messageId} |
Sends push notifications for private messages |
sendMessagesForGroups |
New message in /groupsMessages/{groupId}/{messageId} |
Handles group message notifications and indexing |
deleteMessage |
New request in /deleteMessageRequests/{messageId} |
Handles message deletion with time limits |
| Function Name | Trigger | Purpose |
|---|---|---|
participantAdded |
User added to /groups/{groupId}/users/{userId} |
Handles user addition to groups and group creation events |
participantRemoved |
User removed from /groups/{groupId}/users/{userId} |
Manages user removal and automatic admin assignment |
groupEvents |
New event in /groupEvents/{groupId}/{eventId} |
Broadcasts group events to all members |
| Function Name | Trigger | Purpose |
|---|---|---|
sendNewCallNotification |
New call in /userCalls/{uid}/{callId} |
Sends call notifications including VoIP for iOS |
indexNewCall |
New call in /newCalls/{toId}/{fromId}/{callId} |
Indexes calls and checks for blocked users |
| Function Name | Trigger | Purpose |
|---|---|---|
saveUidOnLogin |
User creation | Maps phone numbers to user IDs for quick lookups |
getVirgilJwt |
HTTPS callable | Generates JWT tokens for end-to-end encryption |
{warning} if you did not deploy Cloud Functions you will see no users. more info
Open your terminal/command prompt and run:
# For Windows/Linux
npm install -g firebase-tools
# For Mac (if permission issues)
sudo npm install -g firebase-tools
Backend - Cloud Functions folderBackend - Cloud Functions foldercmd, then press Enter
cd followed by a spacefirebase login
This opens your browser to sign in to your Google account associated with your Firebase project.
firebase init functions
Follow the prompts:

Before deploying, you must update the package name:
Backend - Cloud Functions/index.js in any text editorconst packageName = "com.packagename.app"Copy these files from Backend - Cloud Functions to the newly created functions directory:
index.js - Main functions filepush-token-sender.js - Handles push notificationsmessage-sender.js - Message delivery logicgenerate-virgil-jwt.js - Encryption token generationpackage.json - Dependencies configuration# Navigate to functions directory
cd functions
# Install required packages
npm install
firebase deploy
Successful deployment should show all function names:

If you encounter network errors during deployment:

{warning} You must be on the Firebase Blaze Plan to deploy Cloud Functions. The free Spark plan doesn't support Cloud Functions.
Test functions locally before deployment:
# Install Firebase emulator
npm install -g firebase-tools
# Start emulator
firebase emulators:start --only functions,database
# Your functions will be available at:
# http://localhost:5001/your-project-id/us-central1/functionName
Monitor function execution and debug issues:
# View all function logs
firebase functions:log
# View logs for specific function
firebase functions:log --only sendMessageNotification
# View real-time logs
firebase functions:log --follow
| Issue | Cause | Solution |
|---|---|---|
| Functions not deploying | Not on Blaze plan | Upgrade to Firebase Blaze plan |
| Syntax errors during deploy | JavaScript errors in code | Check logs, fix syntax errors |
| Function timeout | Function takes too long | Optimize code or increase timeout |
| Permission errors | Missing Firebase permissions | Check IAM roles in Firebase console |
When you encounter issues:
console.log() statements for debugging{info} Remember: Every change to your Cloud Functions requires redeployment using
firebase deploy. Always test your changes thoroughly before deploying to production.
# Essential commands for daily use
firebase login # Authenticate
firebase deploy # Deploy all functions
firebase functions:log # View logs
firebase functions:config:get # View configuration
firebase emulators:start # Start local emulator